//
//  ViewController.m
//  dealData
//
//  Created by  Mac on 2021/3/18.
//

#import "ViewController.h"
#import "GMTAfterSaleModel.h"
#import "OrderGoodsEntityList.h"
#import "OrderListCtl.h"
#import "GMTOurOrderModel.h"


@interface ViewController ()
@property(nonatomic,strong)NSMutableArray * mutArr;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UIButton * button = [UIButton buttonWithType:(UIButtonTypeCustom)];
    button.frame = CGRectMake(50, 220, 120, 40);
    button.layer.cornerRadius = 5;
    [button setTitle:@"info列表" forState:(UIControlStateNormal)];
    [button addTarget:self action:@selector(originAction) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:button];

    
    
    UIButton * button1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    button1.frame = CGRectMake(50, 150, 120, 40);
    button1.layer.borderWidth = 1;
    button1.layer.masksToBounds = YES;
    button1.layer.borderColor = [UIColor blueColor].CGColor;
    
    button1.layer.cornerRadius = 5;
    [button1 setTitle:@"afterinfo列表" forState:(UIControlStateNormal)];
    [button1 setTitleColor:[UIColor blueColor] forState:(UIControlStateNormal)];
    [button setTitleColor:[UIColor blueColor] forState:(UIControlStateNormal)];

    [button1 addTarget:self action:@selector(newAction) forControlEvents:(UIControlEventTouchUpInside)];
    [button1 setTitleColor:[UIColor lightGrayColor] forState:(UIControlStateHighlighted)];
    [button setTitleColor:[UIColor lightGrayColor] forState:(UIControlStateHighlighted)];

    [self.view addSubview:button1];
}

-(void)originAction {
    //    本地取info.json数组
        NSDictionary * dic = [self readLocalDicFileWithName:@"info"];
    //    数据解析
        NSArray * array = dic[@"data"][@"records"];
//    跳到tableview的控制器
    NSMutableArray * arr = [GMTOurOrderModel mj_objectArrayWithKeyValuesArray:array];
    OrderListCtl * vc = [[OrderListCtl alloc] init];
    vc.dataArray = arr;
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)newAction {
//    本地取infoafter.json数组
    NSDictionary * dic = [self readLocalDicFileWithName:@"infoafter"];
//    数据解析
    NSArray * array = dic[@"data"][@"records"];
    //    跳到tableview的控制器
    NSMutableArray * arr = [GMTOurOrderModel mj_objectArrayWithKeyValuesArray:array];
    OrderListCtl * vc = [[OrderListCtl alloc] init];
    vc.dataArray = arr;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark -------- tool

// 读取本地JSON文件
- (NSDictionary *)readLocalDicFileWithName:(NSString *)name {
    // 获取文件路径
    NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"json"];
    // 将文件数据化
    NSData *data = [[NSData alloc] initWithContentsOfFile:path];
    // 对数据进行JSON格式化并返回字典形式
    return [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
}


@end
